home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PASDEMO2 / TASKLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1987-06-08  |  2KB  |  70 lines

  1. program TaskList ; { page 571 }
  2. Const Max = 20 ;
  3. type  ListData = string[ Max ] ;
  4.       ListPointer = ^Item ;
  5.       Item = record
  6.                 Data: ListData ;
  7.                 Next: ListPointer
  8.              end ;
  9. var NullChar: char ;
  10.  
  11. procedure Initialization( var First: ListPointer ) ;
  12.    begin
  13.       First := nil ;
  14.       NullChar := chr( 0 )
  15.    end ;
  16.  
  17. procedure ReadData ( var Name : ListData ) ;
  18.    begin
  19.       repeat
  20.          read( Name ) ;
  21.          if length( Name ) > Max
  22.             then write( '<-- too long ' )
  23.       until length( Name ) <= Max
  24.    end ;
  25.  
  26. procedure FindPrevious( Name: ListData; var PrevElt: ListPointer;
  27.                         First: ListPointer ) ;
  28.    var ListElt: ListPointer ;
  29.  
  30.    function Done : boolean ;
  31.       begin
  32.          if ListElt = nil
  33.             then Done := true
  34.             else Done := ( Name = ListElt^.Data )
  35.       end ;
  36.  
  37.    begin
  38.       PrevElt := First ;
  39.       ListElt := PrevElt^.Next
  40.       while Not Done
  41.          do begin
  42.                PrevElt := ListElt ;
  43.                ListElt := PrevElt^.Next
  44.             end
  45.    end ;
  46.  
  47. procedure AddName( var First: ListPointer ) ;
  48.    var NewItem : ListPointer ;
  49.        OldName : ListData ;
  50.  
  51.    procedure InsertFirst( NewItem: ListPointer; var First: ListPointer ) ;
  52.       begin
  53.          NewItem^.Next := First ;
  54.          First := NewItem
  55.       end;
  56.  
  57.    procedure InsertAfterFirst( NewItem, First: ListPointer ) ;
  58.       var PrevElt: ListPointer ;
  59.       begin
  60.          FindPrevious( OldName, PrevElt, First ) ;
  61.          NewItem^.Next := PrevElt^.Next ;
  62.          PrevElt^.Next := NewItem
  63.       end ;
  64.  
  65.    begin
  66.       New( NewItem ) ;
  67.       write( 'Enter new task=================================================
  68.       write( 'Enter old task which new task should preceed, ' ) ;
  69.  
  70.